<?php

session_start();

// $filename=basename($_SERVER['SCRIPT_NAME'],'.php');


//自动登录(判断当前COOKIE是否选中，用户名和密码是否有值)
if(empty($_SESSION['admin']['username'])&&@$_COOKIE['auto']&&!empty($_COOKIE['username'])&&!empty($_COOKIE['password'])&&empty($_GET['auto'])){

	$_SESSION['admin']['username']=$_COOKIE['username'];

	if($action=='login'){
		header('location:index.php?c=index&a=index&mod=admin');
	}else{
		header('location:index.php?c='.$controller.'&a='.$action.'&mod=admin');
	}

}

if(!empty($_SESSION['admin']['username'])&&$action=='login'){

    header('location:index.php?c=index&a=index&mod=admin');
}



$allow=array('home','');

//判断当前session是否有值，有值表示用户已经登录，否则跳转到登录页
if(empty($_SESSION['admin'])&&$action!='login'&&$action!='logout'&&!in_array($mod,$allow)){
  echo '<script>alert("请先登录");location.href="index.php?c=admin&a=login&mod=admin";</script>';
}


$filename=VIEW_PATH.$mod."/".$controller.'/'.$action.'.html';




//对数据库的配置信息
$config=array(
   'host'=>'127.0.0.1',
   'name'=>'root',
   'password'=>'root',
   'database'=>'p301',
   'charset'=>'utf8'
);


include_once LIB_PATH."function.php";   //引入其他方法
include_once LIB_PATH."page.php";       //引入分页操作
require_once LIB_PATH."mysql.class.php";//引入操作数据库的类
require_once LIB_PATH."upload.php";//引入上传文件
require_once LIB_PATH."thumb.php";//引入缩略图
require_once LIB_PATH."mail.php";//引入发送邮箱

$old=$controller.'/'.$action;
$arr=array('admin/login','index/index');


if(isset($_SESSION['admin'])){
  if(!in_array($old,$_SESSION['admin']['author']['url'])&&!in_array($old,$arr)&&!in_array($mod,$allow)){
    echo '<script>alert("你没有该权限!");location="index.php?c=index&a=index&mod=admin";</script>';
  }

}

